
/*
 * Copyright © 2021 https://www.cestc.cn/ All rights reserved.
 */

package com.zx.learn.flink.source;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.ArrayList;

/**
 * 1.env.fromElements(可变参数);
 * 2.env.fromColletion(各种集合);
 * 3.env.generateSequence(开始,结束);
 * 4.env.fromSequence(开始,结束);
 * <p>
 * 1. 创建环境（流处理环境）
 * 2. 获取数据源
 * 3. 打印数据
 * 4. 执行
 */
public class DataStreamFormElemetSource {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        //1.env.fromElements(可变参数);
        DataStreamSource<String> source1 = env.fromElements("hello world", "hello flink");
        DataStream<String> ds1 = env.fromElements("hadoop", "spark", "flink");
        //2.env.fromColletion(各种集合);
        ArrayList list = new ArrayList();
        list.add("hello hadoop");
        list.add("hello flink");
        DataStreamSource source2 = env.fromCollection(list);
        //3.env.generateSequence(开始,结束);
        DataStreamSource<Long> source3 = env.generateSequence(1, 10).setParallelism(1);
        //4.env.fromSequence(开始,结束);
        DataStreamSource<Long> source4 = env.fromSequence(10, 20);
        //打印输出
        source1.print("source1");
        source2.print("source2");
        source3.print("source3");
        source4.print("source4");
        //执行环境
        env.execute();

    }
}
